<?php

namespace app\admin\controller\mall;

use app\admin\model\MallProfitSharing;
use app\common\controller\AdminController;
//use EasyAdmin\annotation\ControllerAnnotation;
//use EasyAdmin\annotation\NodeAnotation;
use think\App;
use think\facade\Config;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\AddReceiverPlugin;

/**
 * @ControllerAnnotation(title="mall_profit_sharing")
 */
class ProfitSharing extends AdminController
{
    
    use \app\admin\traits\Curd;
    
    public function __construct(App $app)
    {
        parent::__construct($app);
        
        $this->model = new \app\admin\model\MallProfitSharing();
        
    }
    
    /**
     * @NodeAnotation(title="添加")
     */
    public function add()
    {
        
        if ($this->request->isPost()) {
            $post = $this->request->post();
            $rule = [];

            
            $this->validate($post, $rule);
            $post[ 'type' ] = 'MERCHANT_ID';
            $res=MallProfitSharing::addMerchant($post);
            if (!isset($res['account'])){
                $this->error($res['message']);
            }
            try {
                $save           = $this->model->save($post);
            } catch (\Exception $e) {
                $this->error('保存失败:' . $e->getMessage());
            }
            $save ? $this->success('保存成功') : $this->error('保存失败');
        }
        return $this->fetch();
    }
}